﻿
@{
    ViewBag.Title = "Index";
}

<link rel="stylesheet" type="text/css" href="~/Scripts/jquery-easyui-1.10.8/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="~/Scripts/jquery-easyui-1.10.8/themes/icon.css">

<script type="text/javascript" src="~/Scripts/jquery-easyui-1.10.8/jquery.min.js"></script>
<script type="text/javascript" src="~/Scripts/jquery-easyui-1.10.8/jquery.easyui.min.js"></script>
<script>
    $(function () {
        $('#dg').datagrid({
            url: '/Datagrid/GetOrdersPagging',
            queryParams: {},
            method: 'get',
            title: '订单信息',
            iconCls: 'icon-save',

            width: 1200,
            height: 700,

            fitColumns: true,
            autoRowHeight: true,
            //pagingSize: 30,
            pageList: [30, 50, 100, 200, 500, 1000],
            nowwrap: false,
            rownumbers: true,
            pagination: true,

            singleSelect: false,
            ctrlSelect: true,/* 按住ctrl键多选 */
            checkOnSelect: true,
            selectOnCheck: true,

            pageNumber: 9,
            pageSize: 30,

            sortName: 'id',
            sortOrder: 'asc',
            multiSort: true,

            showHeader: true,
            showFooter: true,

            scrollbarSize: 100,
            rownumberWidth: 160,

            editorHeight: 50,

            columns: [[
                {
                    field: '', title: '',
                    checkbox: true /* 显示具有固定宽度复选框 */
                },
                {
                    hidden: false,
                    field: 'id',
                    title: '编号',
                    width: 80,
                    rowspan: 1,
                    colspan: 1,
                    sortable: true,
                    order: 'desc',
                    sorter: function (a, b) {
                        a = a.split('/');
                        b = b.split('/');
                        if (a[2] == b[2]) {
                            if (a[0] == b[0]) {
                                return (a[1] > b[1] ? 1 : -1);
                            } else {
                                return (a[0] > b[0] ? 1 : -1);
                            }
                        } else {
                            return (a[2] > b[2] ? 1 : -1);
                        }
                    },

                    resizable: true,/* 改变列宽 */
                    align: 'center',
                    halign: 'right',/* 'left','right','center' */
                    fixed: true,/* 如果为 true，则防止在“fitColumns”设置为 true 时调整宽度。 */
                    formatter: function (value, row, index) {
                        if (row.user) {
                            return row.user.name;
                        } else if (row.admin) {
                            return '<a>' + value + '</a>';
                        } else {
                            return value;
                        }
                    },
                    styler: function (value, row, index) {
                        if (value < 20) {
                            return 'background-color:#ffee00;color:red;';
                            // the function can return predefined css class and inline style
                            // return {class:'c1',style:'color:red'}
                        }
                    },
                    hformatter: function (title, col) {
                        if (false) {
                            return '<div style="background-color:#ffee00">' + title + '</div>'
                        }
                        return title;
                    },
                    hstyler: function (title, col) {

                    }
                },
                { field: 'orderid', title: '订单号', width: 120 },
                { field: 'seller', title: '卖家', width: 80, align: 'center' },
                { field: 'amount', title: '总价', width: 80, align: 'right' },
                { field: 'mobile', title: '电话', width: 80 },
                { field: 'street', title: '地址', width: 300, align: 'center' }
            ]],
            beforeSend: function () {
                console.log("开始异步请求数据");
            },
            onLoadSuccess: function (index, field, value) {
                console.log("成功加载数据");
            },

            rowStyler: function (index, row) {
                if (false) {
                    return 'background-color:#6293BB;color:#fff;'; // return inline style
                    // the function can return predefined css class and inline style
                    // return {class:'r1', style:{'color:#fff'}};
                }
            },

            //loader: function (param, successCallback, errorCallback) {
            //    return true;
            //},

            loadFilter: function (data) {
                if (data.d) {
                    return data.d;
                } else {
                    return data;
                }
            },

            onHeaderContextMenu: function (e, field) {
                e.preventDefault();
                $(this).datagrid('columnMenu').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            }
        });
    });
</script>

<div>
    <table id="dg" class="easyui-datagrid"> </table>
</div>
